package com.night.card.controller;

import com.github.pagehelper.PageInfo;
import com.night.card.service.interfs.CardInService;
import com.night.card.vo.CardDataVo;
import com.night.common.entity.ResultVo;
import com.night.common.entity.card.Card;
import com.night.common.entity.card.CardIn;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName: CardInController
 * @Description: CardInController
 * @author: CHX42
 * @date: 2022/10/25-10:43
 * @version: v1.0
 */
@RestController
@RequestMapping("/api/cardIn")
public class CardInController {

    @Resource
    private CardInService cardInService;

    @PostMapping("/list")
    public ResultVo<?> list(@RequestBody CardDataVo<CardIn, CardIn> cardDataVo) {
        List<CardIn> cardList = Arrays.asList(cardDataVo.getData());
        cardDataVo.getPageInfo().setList(cardList);
        PageInfo<CardIn> cardInPageInfo = cardInService.getBy(cardDataVo.getPageInfo());
        return new ResultVo<>(cardInPageInfo);

    }

    @PostMapping("/getByCardId")
    public ResultVo<?> getByCardId(@RequestBody CardDataVo<Card, Card> cardDataVo) {
        List<Card> cardList = Arrays.asList(cardDataVo.getData());
        cardDataVo.getPageInfo().setList(cardList);
        return new ResultVo<>(cardInService.getByCardId(cardDataVo.getPageInfo()));

    }

}
